var longestPalindrome = function(s) {

    if (!s) return ''
    let start = 0,
        end = 0,
        n = s.length;
    let len = 0,
        len1 = 0,
        len2 = 0;
    for (let i = 0; i < n; i++) {
        //单字符为中心
        len1 = currentLongest(s, i, i)
            //双字符为中心
        len2 = currentLongest(s, i, i + 1)
        len = Math.max(len1, len2)
            //找到最长回文字符串的起始和结束位置
        if (len > end - start) {
            start = i - Math.floor((len - 1) / 2);
            end = i + Math.floor(len / 2);
        }
    }
    return s.substring(start, end + 1)

};
//左右扩展寻找最长回文长度
function currentLongest(s, left, right) {
    while (left >= 0 && right < s.length && s[left] == s[right]) {
        left--;
        right++;
    }
    return right - left - 1;


};